import * as request from "@/utils/request"

const apiPrefix = "/api/user"

/**
 * 获取用户信息
 */
export function getLoginUser() {
  return request.get<LoginUser>({
    url: apiPrefix + "/get/login"
  })
}

/**
 * 用户登录
 */
export function userLogin(params: UserLoginRequest) {
  return request.post<LoginUser>({
    url: apiPrefix + "/login",
    data: params
  })
}

/**
 * 用户注册
 */
export function userRegister(params: UserRegisterRequest) {
  return request.post<number>({
    url: apiPrefix + "/register",
    data: params
  })
}

/**
 * 用户注销
 */
export function userLogout() {
  return request.post<boolean>({
    url: apiPrefix + "/logout"
  })
}

/**
 * 分页查询用户
 */
export function listUserByPage(params: UserQueryRequest) {
  return request.post<PageUser>({
    url: apiPrefix + "/list/page",
    data: params
  })
}

/**
 * 删除用户
 */
export function deleteUser(params: DeleteRequest) {
  return request.post<boolean>({
    url: apiPrefix + "/delete",
    data: params
  })
}

/**
 * 添加用户
 */
export function addUser(params: UserAddRequest) {
  return request.post<number>({
    url: apiPrefix + "/add",
    data: params
  })
}

/**
 * 更新用户
 */
export function updateUser(params: UserUpdateRequest) {
  return request.post<boolean>({
    url: apiPrefix + "/update",
    data: params
  })
}

/**
 * 获取签到记录
 */
export function getSignInRecord(year: number) {
  return request.get<number[]>({
    url: apiPrefix + "/get/sign_in",
    params: {
      year
    }
  })
}

/**
 * 添加签到记录
 */
export function addSignInRecord() {
  return request.post<boolean>({
    url: apiPrefix + "/add/sign_in"
  })
}
